package com.lord.demo.producer;

import javax.annotation.Resource;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import com.lord.demo.entity.Order;

@Component
public class OrderSender {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void send(Order order) throws Exception {

        /**
         * order 消息体内容
         * correlationData 消息唯一ID
         */
        CorrelationData correlationData = new CorrelationData();
        correlationData.setId(order.getMessageId());

        // 发送消息到rabbitmq
        rabbitTemplate.convertAndSend("order-exchange", "order.abcd", order, correlationData);

        /**
         * 还要在 rabbitmq 控制台配置exchange和queue，并绑定
         * 加绑定在控制台的exchange和queues哪一块都可以
         */
    }
}
